/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package cn.ekuma.data.dao;
import cn.ekuma.data.dao.bean.IKeyed;

import com.openbravo.data.basic.BasicException;
import com.openbravo.data.loader.DataRead;
import com.openbravo.data.loader.PreparedSentence;
import java.util.List;

/**
 *
 * @author Administrator
 */
public abstract class InfoDAO<T extends IKeyed,V extends BaseDAO> extends ViewDAO<T>{
    private int[] columnIndexs;
    protected V base;

    public InfoDAO(V base) {
        this(base,base.getTableDefinition().getAllFields());
    }

    public InfoDAO(V base,int[] columnIndexs) {
        super(base.s);
        this.base=base;
        this.columnIndexs=columnIndexs;
    }

    @Override
    public List<T> list() throws BasicException {
        return new PreparedSentence(s, base.getTableDefinition().getListSQL(columnIndexs), null,  this).list();
    }

    public T find(IKeyed f) throws BasicException {
        return (T) new PreparedSentence(s,base.getTableDefinition().getFindSQL(columnIndexs),base.getKeySerializerWrite(),this).find(f);
    }

    public String getListSQL(){
        return base.getTableDefinition().getListSQL(columnIndexs);
    }

    public String getListSQL(String p){
        return base.getTableDefinition().getListSQL(p,columnIndexs);
    }
    
}
